package com.h3c.nem.controller;

import com.eos.common.constant.StatusCodeEnum;
import com.eos.common.util.Result;
import com.h3c.nem.dto.TbOfferStudyDTO;
import com.h3c.nem.dto.TbOfferStudySaveDTO;
import com.h3c.nem.service.ITbOfferStudyService;
import com.h3c.nem.utils.AppBusinessException;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 学历信息控制层
 *
 * @author chenyifan
 * @since 2022-06-06 11:42:52
 */
@Slf4j
@CrossOrigin
@RestController
@AllArgsConstructor
@RequestMapping("/tbOfferStudy")
public class TbOfferStudyController {
    /**
     * 服务对象
     */
    private final ITbOfferStudyService tbOfferStudyService;

    /**
     * 保存学历信息
     *
     * @param studySaveDTO
     * @return
     */
    @PostMapping("/saveStudyInfo")
    public Result<String> saveStudyInfo(@RequestBody TbOfferStudySaveDTO studySaveDTO) {
        try {
            tbOfferStudyService.saveStudyInfo(studySaveDTO);
            return new Result(true, StatusCodeEnum.NORMAL);
        } catch (AppBusinessException e) {
            log.error(e.getMessage());
            //有校验异常时返回状态码401给前端弹窗提醒
            return new Result(false, 401, e.getMessage());
        } catch (Exception e) {
            log.error("", e);
            return new Result(false, StatusCodeEnum.ADD_FAIl);
        }
    }

    /**
     * 校验学历信息填写是否符合规则公共接口
     *
     * @return
     */
    @PostMapping("/judgeStudyInfo")
    public Result<String> judgeStudyInfo(@RequestBody List<TbOfferStudyDTO> studyDTOS) {
        try {
            return new Result(true, StatusCodeEnum.NORMAL, tbOfferStudyService.judgeStudyInfo(studyDTOS));
        } catch (Exception e) {
            log.error(e.getMessage());
            return new Result(false, StatusCodeEnum.SEARCH_FAIl);
        }
    }


    /**
     * 回显学历信息
     *
     * @return
     */
    @GetMapping("/showStudyInfo")
    public Result<String> showStudyInfo() {
        try {
            return new Result(true, StatusCodeEnum.NORMAL, tbOfferStudyService.showStudyInfo());
        } catch (Exception e) {
            log.error(e.getMessage());
            return new Result(false, StatusCodeEnum.SEARCH_FAIl);
        }
    }
}

